// *** LICENSE HEADER ***
// Filename: ./main.cpp
// This file is part of Nodewarz 0.1
// Nodewarz is a 3d OpenGL strategy game
// Copyright (C) 2007 CZestmyr
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// *** END LICENSE HEADER ***
#include "main.h"

int main(int argc, char* argv[]) {
    //Default log file name
    char* logFile = "log.txt";

    //Parse the program arguments
    for (int i = 1; i < argc; ++i){
        //Set the log file as defined by the "-l" switch
        if (i+1 < argc && !strcmp("-l", argv[i]) ){
            logFile = argv[i+1];
            ++i;
        }
    }

    //Create the game engine
    engine theEngine(logFile);

    //Init randomizer
    srand(time(0));

    int result = 0;

    //Try to Init the engine
    if (theEngine.Init()) {
        //Try to create the program window
        if (theEngine.SDLCreateWindow()) {
            //Main program loop
            while (theEngine.Run()) {
                theEngine.Update();
                theEngine.Draw();

                SDL_Delay(20);
            }
        } else result = 1;
        theEngine.Deinit();
    } else result = 1;

    return result;
}
